package com.gary.jstackDemo;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author peng_rui
 * @date 2022/3/12
 */
public class JstackThreadPrint0To100 {
    public static void main(String[] args) {
        AtomicInteger count = new AtomicInteger();

        new Thread(() -> {
            while (count.get() < 100) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (JstackDeadLock.class) {
                    System.out.println(Thread.currentThread() + "--> " + count.getAndIncrement());
                }
            }

        }, "A-Thread").start();

        new Thread(() -> {
            while (count.get() < 100) {
                synchronized (JstackDeadLock.class) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread() + "--> " + count.getAndIncrement());
                }

            }
        }, "B-Thread").start();
    }
}
